package ar.edu.utn.injectors;

import java.util.List;

import javax.naming.InsufficientResourcesException;

import ar.edu.utn.exceptions.ReflectionException;
import ar.edu.utn.xcontainer.ComposeComponentDescription;

public class ConstructorInyector {
	
	private ComposeComponentDescription componentDescription;
	
	public ConstructorInyector(ComposeComponentDescription componentDescription){
		this.componentDescription=componentDescription;
		
	}
	
	public Object inyectComponent(ComposeComponentDescription componentDescription) throws ReflectionException{
		ConstructorArguments arguments=componentDescription.getClassConstructorArguments();
		Object instanceComponent=new Object();
		if (isDefaultConstructor(arguments)){
			try{
				instanceComponent= componentDescription.getComponentClass().newInstance();
			}catch(InstantiationException e1){
				throw new ReflectionException("No se pudo instanciar la clase del componente" + componentDescription.getComponentKey(), e1.getCause());
			}catch (IllegalAccessException e2) {
				throw new ReflectionException(e2.getMessage(), e2.getCause());
			}catch (ClassNotFoundException e3) {
				throw new ReflectionException("No se pudo encontrar la clase" + componentDescription.getComponentKey(), e3.getCause());
			}
			
			
		}
		else {
			while(false){
				
			}
			
		}
		return instanceComponent;
		
	}
	protected boolean isDefaultConstructor(ConstructorArguments constructorArguments){
		return constructorArguments.getArguments().isEmpty();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
		
	}
	
	
	
	

